package com.zuqiuzhandui.liveing.view.choose;

import android.content.Context;

import com.zuqiuzhandui.liveing.model.resultModel.LiveCreateRs;
import com.zuqiuzhandui.liveing.model.resultModel.TeamListRs;
import com.zuqiuzhandui.liveing.model.resultModel.TeamScheduleRs;
import com.zuqiuzhandui.liveing.net.HttpMethods;
import com.zuqiuzhandui.liveing.net.ProgressSubscriber;
import com.zuqiuzhandui.liveing.net.SubscriberOnNextListener;
import com.zuqiuzhandui.liveing.net.UrlFactory;
import com.zuqiuzhandui.testing.myhelper.util.HashMapProxy;

import java.util.List;
import java.util.Map;

/**
 * Created by yq on 2016-10-13.
 */

public class ChoosePresenter implements ChooseContract.Presenter {
    ChooseContract.View view;

    public ChoosePresenter(ChooseContract.View view) {
        this.view = view;
        this.view.setPresenter(this);
    }

    @Override
    public void requestTeam() {
        Map<String, String> map = UrlFactory.getAccessKeyMap();
        HttpMethods.getInstance().postTeamListGet(new ProgressSubscriber<List<TeamListRs>>(new SubscriberOnNextListener<List<TeamListRs>>() {
            @Override
            public void onNext(List<TeamListRs> dataList) {
                if (!view.isActive()) {
                    return;
                }
                view.showSuccessTeam(dataList);
            }
        }, (Context) view), map);
    }

    @Override
    public void requestTeamSchedule(String teamCode) {
        Map<String, String> map = UrlFactory.getAccessKeyMap();
        map.put("code", teamCode);
        HttpMethods.getInstance()
                .postTeamScheduleGet(new ProgressSubscriber<List<TeamScheduleRs>>(new SubscriberOnNextListener<List<TeamScheduleRs>>() {
                    @Override
                    public void onNext(List<TeamScheduleRs> data) {
                        if (!view.isActive()) {
                            return;
                        }

                        view.showSuccessTeamSchedule(data);
                    }
                }, (Context) view),map);
    }

    @Override
    public void requestLiveCreate(String teamCode, String typeCode, String liveType) {
        Map<String,String> map=UrlFactory.getAccessKeyMap();
        ((HashMapProxy) map)
                .putObject("teamCode",teamCode)
                .putObject("typeCode",typeCode)
                .putObject("liveType",liveType);
        HttpMethods.getInstance()
                .postLiveCreate(new ProgressSubscriber<LiveCreateRs>(new SubscriberOnNextListener<LiveCreateRs>() {
                    @Override
                    public void onNext(LiveCreateRs rs) {
                        if (!view.isActive()) {
                            return;
                        }
                        view.showSuccessLiveCreate(rs);
                    }
                }, (Context) view),map);

    }


}
